///////////////////////////////////////////////////
// Election Administration Polarization
// Plot RD Estimates Over Time
///////////////////////////////////////////////////

* Set the working directory
gl path "~/Library/CloudStorage/GoogleDrive-danmckinleythompson@gmail.com/My Drive/ElecAdminPolarization/How_Partisan_Is_Local_Election_Admin_Replication"


////
// Plotting the effect on presidential vote share over time
////

* Bring in the presidential election analysis data
use "$path/analysis_data/rd_election_analysis_data.dta", clear
keep if office=="pres"

* Run separate regressions by year
matrix define B = J(5, 4, .)
local row = 1
forval y=2004(4)2020 {
	rdrobust r_oos_state_year_vs_dem rv if policy_year==`y', vce(cluster election_id)
	matrix B[`row', 1] = e(tau_cl)
	matrix B[`row', 2] = e(tau_cl) - 1.96*e(se_tau_cl)
	matrix B[`row', 3] = e(tau_cl) + 1.96*e(se_tau_cl)
	matrix B[`row', 4] = `y'
	local row = `row' + 1
}
svmat B
keep B*
rename (B1 B2 B3 B4) (b lower upper year)

* Plot the estimates over time
twoway (rcap lower upper year, lc(gs10) mc(gs10)) ///
	(scatter b year, mc(gs4)), ///
	yli(0, lc(gs2) lp(dash)) ///
	ysc(r(-0.06 0.1)) ylab(-0.06(0.02)0.1) ///
	xsc(r(2003 2021)) xlab(2004(4)2020) scale(1.2) ///
	xti("Year") yti("Effect on Dem Pres Vote") ///
	legend(off) scheme(s2color) graphregion(color("white"))
graph export "$path/output/rd_dem_vs_over_time.pdf", replace
